<%inherit file="/master.html"/>
<% import datetime %>
<%def name="head()">
<script language='javascript'>
$(document).ready(function()
{
    $('table td img.delete').click(function(){
        var answer = confirm("Are you sure you want to delete this device? Please note that this will also delete any values associated with this device!")
        if (answer){
            var elem = $(this)
            id = $(this).parent().parent().parent().attr('id')
            var dataString = 'id=' + id;
            
            $.ajax({
                type: "POST",
                url: "/device_del", 
                data: dataString,
                success: function(data) {
                            elem.parent().parent().parent().remove();
                         }
            });
        }   
        return false;
    });
}
</script>
</%def>

<%def name="content()">
<div id="output"></div>
<table cellspacing="0" cellpadding="0" align="center" width="100%" id="devices">
	<tbody>
		<tr>
			<td class="HeadText">SWAP network information</td>
		</tr>
		<tr>
			<td class="body info">
				<p>This page displays general information about the nodes in the SWAP network.</p>
			</td>
		</tr>
		<tr>
			<td class="body">
				<table class="InfoTable" cellspacing="0" cellpadding="0" border="0" width="60%">
					<tbody>
						<tr class="HeadTable">
							<td nowrap="" width="5%">Address</td>
							<td nowrap="" width="10%">Manufacturer</td>
							<td nowrap="" width="20%">Product</td>
							<td nowrap="" width="15%">Sleeping</td>
							<td nowrap="" width="15%">Last update</td>
							<td nowrap="" width="15%">Option</td>
						</tr>
						% for mote, details in result.iteritems():               
						  <tr class="Row">
							  <td>${details["address"]}</td>
							  <td>${details["manufacturer"]}</td>
							  <td>${details["product"]}</td>
							  <td>${details["sleeping"]}</td>
							  <td>${details["lastupdate"]}</td>
                % if str(details["address"]) in addrindb:
  							  <td><a href="#delete"><img class="delete" border="0" src="/images/delete.png"></a></td>
                % else:
  							  <td><a href="/swap_add?mote=${details['address']}&product=${details['product']}&pluginguid=${pluginguid}&pluginid=${pluginid}"><img name="Add this device to the database" class="delete" border="0" src="/images/add.png"></a></td>																						
                % endif
						</tr>
						% endfor
					</tbody>
				</table>
			</td>
		</tr>
	</tbody>
</table>
</%def>
